#include "Ctrl.h"

#if ChainOfResponsibility_


class Request
{
private:
	string m_requestType;
public:
	void SetRequestType(const string _value) {
		m_requestType = _value;
	}
	string GetRequestType()const {
		return m_requestType;
	}
private:
	string m_requestContent;
public:
	void SetRequestContent(const string _value) {
		m_requestContent = _value;
	}
	string GetRequestContent()const {
		return m_requestContent;
	}
private:
	int m_number;
public:
	void SetNumber(const int _value) {
		m_number = _value;
	}
	int GetNumber()const {
		return m_number;
	}
};





class Manager
{
protected: 
	string m_name;
	// 管理者的上级
	Manager* m_pSuperior; 
public:
	Manager(string _name) {
		m_name = _name;
	}
	// 设置管理者的上级
	void SetSuperior(Manager* _pSuperior) {
		m_pSuperior = _pSuperior;
	}
	// 申请请求
	virtual void RequestApplications(Request* _request) = 0;
};

// 经理
class CommonManager : public Manager
{
public :
	CommonManager(string _name) : Manager(_name){}
	void RequestApplications(Request* _request) override {
		if (_request->GetRequestType() == "请假" && _request->GetNumber() <= 2) {
			cout << m_name << "：" << _request->GetRequestContent() << "数量" << _request->GetNumber() << " 被批准！" << endl;
		}
		else {
			if (m_pSuperior != nullptr) {
				m_pSuperior->RequestApplications(_request);
			}
		}
	}
};

// 总监
class Majordomo : public Manager
{
public:
	Majordomo(string _name) : Manager(_name) {}
	void RequestApplications(Request* _request) override {
		if (_request->GetRequestType() == "请假" && _request->GetNumber() <= 5) {
			cout << m_name << "：" << _request->GetRequestContent() << "数量" << _request->GetNumber() << " 被批准！" << endl;
		}
		else {
			if (m_pSuperior != nullptr) {
				m_pSuperior->RequestApplications(_request);
			}
		}
	}
};

// 总经理
class GeneralManager : public Manager
{
public:
	GeneralManager(string _name) : Manager(_name) {}
	void RequestApplications(Request* _request) override {
		if (_request->GetRequestType() == "请假") {
			cout << m_name << "：" << _request->GetRequestContent() << "数量" << _request->GetNumber() << " 被批准！" << endl;
		}
		else if(_request->GetRequestType() == "加薪" && _request->GetNumber() <= 500) {
			cout << m_name << "：" << _request->GetRequestContent() << "数量" << _request->GetNumber() << " 被批准！" << endl;
		}
		else if (_request->GetRequestType() == "加薪" && _request->GetNumber() > 500) {
			cout << m_name << "：" << _request->GetRequestContent() << "数量" << _request->GetNumber() << " 再说吧！" << endl;
		}
	}
};

int main() {
	CommonManager* pJingli = new CommonManager("经理");
	Majordomo* pZongjian = new Majordomo("总监");
	GeneralManager* pZongjingli = new GeneralManager("总经理");
	pJingli->SetSuperior(pZongjian);
	pZongjian->SetSuperior(pZongjingli);

	Request* pRequest = new Request();
	pRequest->SetRequestType("请假");
	pRequest->SetRequestContent("小菜请假");
	pRequest->SetNumber(1);
	pJingli->RequestApplications(pRequest);

	Request* pRequest2 = new Request();
	pRequest2->SetRequestType("请假");
	pRequest2->SetRequestContent("小菜请假");
	pRequest2->SetNumber(4);
	pJingli->RequestApplications(pRequest2);

	Request* pRequest3 = new Request();
	pRequest3->SetRequestType("加薪");
	pRequest3->SetRequestContent("小菜请求加薪");
	pRequest3->SetNumber(500);
	pJingli->RequestApplications(pRequest3);

	Request* pRequest4 = new Request();
	pRequest4->SetRequestType("加薪");
	pRequest4->SetRequestContent("小菜请求加薪");
	pRequest4->SetNumber(1000);
	pJingli->RequestApplications(pRequest4);


}




#endif